package Day2025_04_03;

public class LeetCode1783 {
    int sum;
    int path;
    public int subsetXORSum(int[] nums) {
        sum = 0;
        path = 0;
        dfs (nums, 0);
//        dfs2 (nums, 0);
        return sum;
    }
    private void dfs (int[] nums, int pos) {
        if (pos == nums.length) {
            sum += path;
            return;
        }

        // 选
        path ^= nums[pos];
        dfs (nums, pos + 1);

        // 恢复现场
        path ^= nums[pos];

        // 不选
        dfs (nums, pos + 1);
    }

    private void dfs2 (int[] nums, int pos) {
        sum += path;
        for (int i = pos; i < nums.length; i++) {
            path ^= nums[i];
            dfs2 (nums, i + 1);
            path ^= nums[i];
        }
    }
}
